const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT'

const baseURL = 'https://qdwlkj.cn'; //配置的域名

function request(method, url, data, header = {
  'content-type': 'application/json',
}) {
  return new Promise(function (resolve, reject) {
    wx.request({
      url: baseURL + url,
      method: method,
      data: method === POST ? JSON.stringify(data) : data,
      header: header,
      success(res) {
        resolve(res);
      },
      fail(err) {
        //请求失败
        reject(err)
      }
    })
  })
}


//接口可以集合到一块，集中管理
const API = {
  home: {
    getList: (data) => request(GET, '/moments/list', data),
    getFocusList: (data) => request(GET, '/moments/getMyFocusMoments', data),
    getSchoolList: (data) => request(GET, '/school/list', data)
  },
  dynamics: {
    addMoment: (data) => request(POST, '/moments/add', data)
  },
  detail: {
    getDetail: (data) => request(GET, '/moments/getById', data),
    addComment: (data) => request(POST, '/comment/addFirstComment', data),
    focus: (data) => request(POST, '/account/focus', data),
    deleteFocus: (data) => request(POST, '/account/deleteFocus', data),
  },
  login: {
    login: (data) => request(GET, '/account/login', data)
  },
  mine:{
    getMyList:(data) => request(GET, '/moments/getMymoments', data),
    updateInfo:(data) => request(POST, '/account/update', data),
    getQRCode:(data) => request(GET, '/account/generateQRCode', data),

  },
  ask:{
    getAskList:(data) => request(GET, '/questionnare/list', data),
    getAskDetail:(data) => request(GET, '/questionnare/getById', data),
    addAsk:(data) => request(POST, '/questionnare/add', data),
    addAnswer:(data) => request(POST, '/questioncomment/addFirstComment', data),
  },
  ad:{
    getAdList:(data) => request(GET, '/advisement/list', data),
    addAd:(data) => request(POST, '/advisement/add ', data),
  },
  fans:{
    getFans:(data) => request(GET, '/account/getMyInvited', data),
  },
  addLike: (data) => request(PUT, `/moments/addLike?momentId=${data.momentId}&openId=${data.openId}`),
  deleteLike: (data) => request(PUT, `/moments/deleteLike?momentId=${data.momentId}&openId=${data.openId}`),
  addStore: (data) => request(PUT, `/moments/addStore?momentId=${data.momentId}&openId=${data.openId}`, data),
  deleteStore: (data) => request(PUT, `/moments/deleteStore?momentId=${data.momentId}&openId=${data.openId}` , data),
  updateInfo: (data) => request(POST, '/account/add ', data),
};
module.exports = {
  API: API
}